/****************************************************************
 *
 * Project: Handle ARM M4 STM32F407VG In 2 Weeks
 * 
 ****************************************************************/

/****************************************************************
 *
 *	Module		: "header file" myUsart.h
 *  Tool		: KeilC ARM 4.22a
 *	Chip		: STM32F407VG
 * 	History		: 9/12/2011
 *	Description	: Day 7
				  + My library to exchange data via Usart peripheral
				  + Reference to header file "myUsart.c"
 *				
 *	Author		: Dang Anh Tung			
 *	Description	: www.payitforward.edu.vn
 *				
 *
 ****************************************************************/

 
 /****************************************************************
 * 							IMPORT
 ****************************************************************/
 #include "stm32f4xx.h"
 #include "stm32f4xx_usart.h"
 #include "stm32f4xx_dma.h"


/*****************************************************************
* 							DEFINE
******************************************************************/
#define DMA_USART1_TX_STREAM		DMA2_Stream7	
#define DMA_USART1_TX_CHANNEL		DMA_Channel_4
#define	DMA_USART1_TX_PERIPH		(uint32_t)USART1 + 0x04
#define DMA_USART1_TX_PRIORITY		DMA_Priority_High
#define DMA_USART1_TX_STREAM_IRQ	DMA2_Stream7_IRQn
		

#define DMA_USART1_RX_STREAM		DMA2_Stream5   	
#define DMA_USART1_RX_CHANNEL		DMA_Channel_4
#define	DMA_USART1_RX_PERIPH		(uint32_t)USART1 + 0x04
#define DMA_USART1_RX_PRIORITY		DMA_Priority_VeryHigh
#define DMA_USART1_RX_STREAM_IRQ	DMA2_Stream5_IRQn


#define DMA_USART2_TX_STREAM		DMA1_Stream6   	
#define DMA_USART2_TX_CHANNEL		DMA_Channel_4
#define	DMA_USART2_TX_PERIPH		(uint32_t)USART2 + 0x04
#define DMA_USART2_TX_PRIORITY		DMA_Priority_High
#define DMA_USART2_TX_STREAM_IRQ	DMA1_Stream6_IRQn

#define DMA_USART2_RX_STREAM		DMA1_Stream5  
#define DMA_USART2_RX_CHANNEL		DMA_Channel_4
#define	DMA_USART2_RX_PERIPH		(uint32_t)USART2 + 0x04
#define DMA_USART2_RX_PRIORITY		DMA_Priority_VeryHigh
#define DMA_USART2_RX_STREAM_IRQ	DMA1_Stream5_IRQn

#define DMA_UART4_TX_STREAM			DMA1_Stream4	
#define DMA_UART4_TX_CHANNEL		DMA_Channel_4
#define	DMA_UART4_TX_PERIPH			(uint32_t)UART4 + 0x04
#define DMA_UART4_TX_PRIORITY		DMA_Priority_High
#define DMA_UART4_TX_STREAM_IRQ	    DMA1_Stream4_IRQn

#define DMA_UART4_RX_STREAM			DMA1_Stream2	
#define DMA_UART4_RX_CHANNEL		DMA_Channel_4
#define	DMA_UART4_RX_PERIPH			(uint32_t)UART4 + 0x04
#define DMA_UART4_RX_PRIORITY		DMA_Priority_VeryHigh
#define DMA_UART4_RX_STREAM_IRQ	    DMA1_Stream2_IRQn



 /****************************************************************
 * 							GLOBAL
 ****************************************************************/


/*
extern DMA_InitTypeDef DmaUsart1TxStruct; 
extern char DmaUsart1TxBuffer[20];

extern DMA_InitTypeDef DmaUsart1RxStruct;
extern char DmaUsart1RxBuffer[20];

extern DMA_InitTypeDef DmaUsart2TxStruct;
extern char DmaUsart2TxBuffer[20];

extern DMA_InitTypeDef DmaUsart2RxStruct;
extern char DmaUsart2RxBuffer[20];	  

extern DMA_InitTypeDef DmaUart4TxStruct;
extern char DmaUart4TxBuffer[20];

extern DMA_InitTypeDef DmaUart4RxStruct;
extern char DmaUart4RxBuffer[20];
*/


 /****************************************************************
 * 						   FUNCTIONS
 ****************************************************************/

//Init all USART/UART peripheral that will be used in IMU
void myUsartInit(void);

//Init DMA for all USART/UART peripheral that will be used in IMU
void myDmaUsartInit(void);

//Init Interrupt for all USART/UART peripheral that will be used in IMU
void myDmaUsartInterruptInit(void);

//USART/UART send bytes/String by normal bus
void myUsartSendBytes(USART_TypeDef* USARTx, uint8_t *byte,uint32_t numByte);

//USART/UART send bytes/String by DMA bus
void myUsartSendDma(DMA_Stream_TypeDef* DMAy_Streamx, USART_TypeDef* USARTx, uint8_t *sendBuf, uint32_t numByte);

